<!--业务接单-->
<template>
  <el-form :inline="true" :label-position="'right'"  class="demo-form-inline">
    <el-form-item label="任务">
      <el-input disabled="" v-model="Form.TASK_NAME.value" placeholder="任务"></el-input>
    </el-form-item>
    <el-form-item label="节点">
      <el-input disabled="" v-model="Form.ORG_NAME.value" placeholder="节点"></el-input>
    </el-form-item>
    <el-form-item required label="处理情况">
      <el-select  v-model="Form.RESULT.value" placeholder="处理情况" width="90%">
        <el-option label="完成" value="50250001"></el-option>
        <el-option label="未完成" value="50250002"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="填报人">
      <el-input disabled v-model="Form.USER_NAME.value" placeholder="填报人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话">
      <el-input disabled v-model="Form.LINK_TEL.value" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="填报期限">
      <el-input disabled v-model="Form.TASK_REQ_DATE.value" placeholder="填报期限"></el-input>
    </el-form-item>
    <el-form-item  label="填报时间">
      <el-input disabled v-model="Form.TASK_OPR_DATE.value" placeholder="填报时间"></el-input>
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="Form.TASK_COMMENT.value" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item class="btnDir">
      <el-button @click="onSubmit">保 存</el-button>
      <el-button @click="onCancel">取 消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
import { mapState } from "vuex";
export default {
 components: {
		requestUtil,
		CustOrderService,
  },
  computed: {
		...mapState("orders", ["orderItemList"]),
		...mapState("user", ["user"]),
	},
  async mounted(){
    
    if(this.CTOInfo instanceof Array){
      this.newCTOInfo = this.CTOInfo;
    }else{
      this.newCTOInfo = [this.CTOInfo];
    }
    
    if(this.newCTOInfo.length > 0){
      var orderItemIds="";

      this.Form.USER_NAME.value = this.user.staffName;
      this.Form.USER_ID.value = this.user.staffId;
      this.Form.TASK_OPR_DATE.value = this.$util.dateFormat(new Date(),"yyyy-MM-dd");

      for(var i=0;i<this.newCTOInfo.length;i++){
         if(i==0){
           orderItemIds += this.newCTOInfo[i].orderItemId;
         }else{
            orderItemIds += ","+this.newCTOInfo[i].orderItemId;
         }
      }
      var scopeInfos=[]
      scopeInfos.push({scope:"orderTasks"});
      var custSoNumber = this.newCTOInfo[0].custSoNumber;
      var batchNbr =  this.newCTOInfo[0].batchNbr;
      var custId = this.newCTOInfo[0].custId;
      var taskId = this.newCTOInfo[0].taskId;


      this.orderItemIds = orderItemIds;


    let usersMsg = {
        acceptUserId: this.user.staffId,
        acceptUserOrg: this.user.orgId,
        systemUserId: this.user.sysUserId,
        dealType: 234,
        orderItemId:this.newCTOInfo[0].orderItemId,
        orderAuditId:this.newCTOInfo[0].orderAuditId
      };
      // 工单级别dealType:1 销售品级别dealType:234
      const result = await CustOrderService.queryOrderItemDealTask(usersMsg);

       const orderDetailOrders = await CustOrderService.qryCustomerOrderDetail({custSoNumber,batchNbr,orderItemIds,custId,scopeInfos});

      

      var  orderTasks = result.meta.orderItemDealTasks;
      // var orderTasks = this.ODKInfo;

      for(var i=0;i<orderTasks.length;i++){
        //业务接单
        if(orderTasks[i].taskId == 'TACHE20490001'){
          var orderTask = orderTasks[i];
          break;
        }
      }

     
      var orderDetailTasks = orderDetailOrders.orderDetails[0].orderTasks;
      
      for(var i=0;i<orderDetailTasks.length;i++){
        //业务接单
        if(orderDetailTasks[i].taskId == 'TACHE20490001'){
          var orderDetailTask = orderDetailTasks[i];
          break;
        }
      }

       this.Form.TASK_NAME.value = "业务接单";
      this.orderTask = orderTask;
      
      // 

      this.Form.TASK_REQ_DATE.value = orderDetailTask.taskReqDate;
      this.Form.LINK_TEL.value = orderDetailTask.linkTel;
      // this.Form.ORG_NAME.value = orderTask.oprOrgId;
      var orgName = await CustOrderService.getOrgName({orgId:this.user.orgId});
      
       this.Form.ORG_NAME.value = orgName;
    }else{
      this.Form.TASK_NAME.value = "";
    }


  },
  watch:{

  },
  props:{
	  	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
	CTOInfo: {
			type: [Array,Object],
			default: () => {
				return [];
			},
		},
  },
  data() {
    return {
    orderItemIds:"",
    newCTOInfo:[],
    orderTask:{},
     Form:{
	"TASK_NAME":{
		  type: 'Ipt',
          name: '任务',
          colId: "TASK_NAME",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-141000049",
          disabled: true,
          show: true,
          span: 6
	},
	"RESULT":{
		 type: 'Ipt',
          name: '处理情况',
          colId: "RESULT",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "RESULT",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-141000046",
          disabled: true,
          show: true,
          span: 6
	},
	"USER_NAME":{
		type: 'Ipt',
          name: '填报人',
          colId: "USER_NAME",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "USER_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100012377",
          disabled: true,
          show: true,
          span: 6
	},
	"ORG_NAME":{
		type: 'Ipt',
          name: '节点',
          colId: "ORG_NAME",
          colType: "C",
          tableName: "ORGANIZATION",
          fieldId: "ORG_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"LINK_TEL":{
		type: 'Ipt',
          name: '联系电话',
          colId: "LINK_TEL",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "LINK_TEL",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"TASK_REQ_DATE":{
		type: 'Ipt',
          name: '填报期限',
          colId: "TASK_REQ_DATE",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_REQ_DATE",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"TASK_OPR_DATE":{
		type: 'Ipt',
          name: '填报时间',
          colId: "TASK_OPR_DATE",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_OPR_DATE",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"TASK_COMMENT":{
		type: 'Ipt',
          name: '备注',
          colId: "TASK_COMMENT",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_COMMENT",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	},
	"USER_ID":{
		type: 'Ipt',
          name: 'USER_ID',
          colId: "USER_ID",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "USER_ID",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "14441-100013995",
          disabled: true,
          show: true,
          span: 6
	}
	}
	}
  },
  methods: {

	 onCancel(){
		
     this.$emit("close");
	},
    async onSubmit() {
	  
	let msJson = {
    statusCds: this.newCTOInfo[0].statusCd, //订单状态
    custSoNumber: this.newCTOInfo[0].custSoNumber, //流水号  从上个页面带回
    handleOrgId: this.user.staffId,
    custId: this.newCTOInfo[0].custId,
    batchNbr: this.newCTOInfo[0].batchNbr, //批次号
		accNum: "", //设备号,没有不传
		orderItemIds:this.orderItemIds,
		taskId:this.orderTask.taskId,
		orderAuditId:this.newCTOInfo[0].orderAuditId,
    oneOrmany:"one",
    orderTaskId:this.orderTask.orderTaskId,
    userId:this.user.staffId,
    orderItemId:this.orderItemIds,
    processInstId:this.orderTask.processInstId,
    activityId:this.orderTask.activityInstId

      };

		let param = requestUtil.paramEnc(this.Form,msJson);


		

		var result = await CustOrderService.saveOrderTask({...msJson,...param});
    
    this.$emit("windowClose");
    if(result.code == 200){
       this.$confirm("业务接单成功！", "提示", {
        confirmButtonText: "确定",
        showCancelButton: false,
        type: "success",
        center: true
      });
    }else{
       this.$confirm(result.meta, "提示", {
        confirmButtonText: "确定",
        showCancelButton: false,
        type: "success",
        center: true
      });
    }
    this.onCancel();
    }
  }
};
</script>

<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
  width: 42%;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
</style>
